package com.company.practice;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Pattern;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/11/3 5:22
 */
public class Test1 {

}


class DirList{
    public static void main(String[] args) {

        //fun1();
        fun2();
    }
    /**
     * 获取当前文件夹所有文件
     */
    static void fun1(){
        File path = new File(".");
        String[] list;
        list = path.list();
        for (String s :
                list) {
            System.out.println(s);
        }
    }

    /**
     *
     */
    static void fun2(){
        File path = new File(".");
        String[] list;
        MyFilenameFilter myFilenameFileter = new MyFilenameFilter();
        list = path.list(myFilenameFileter);
        for (String s :
                list) {
            System.out.println(s);
        }
    }
}

class MyFilenameFilter implements FilenameFilter {
    String regex = "";

    private Pattern pattern = Pattern.compile(regex);
    @Override
    public boolean accept(File dir, String name) {

        return pattern.matcher(name).matches();
    }
}


